package com.yfq;

import com.yfq.springframework.beans.PropertyValue;
import com.yfq.springframework.beans.PropertyValues;
import com.yfq.springframework.beans.config.BeanDefinition;
import com.yfq.springframework.beans.config.BeanFactoryPostProcessor;
import com.yfq.springframework.beans.factory.ConfigurableListableBeanFactory;
import com.yfq.springframework.beans.support.DefaultListableBeanFactory;

/**
 * @author: yfq
 * @date: 2023/1/29 17:14
 * @description:
 */
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessorBeanFactory(ConfigurableListableBeanFactory beanFactory) {
//        beanFactory
        if (beanFactory instanceof DefaultListableBeanFactory) {
            DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory;
            PropertyValues propertyValues = new PropertyValues();
            propertyValues.addPropertyValue(new PropertyValue("name", "西游记"));
            propertyValues.addPropertyValue(new PropertyValue("price", 20));
            defaultListableBeanFactory.registerBeanDefinition("book", new BeanDefinition(Book.class, propertyValues));
        }
        System.out.println("MyBeanFactoryPostProcessor方法执行...");
    }
}
